﻿#include<iostream>
#include<string>
using namespace std;

class Manager
{
protected:
	Manager *m_manager;
	string m_name;
public:
	Manager(Manager *manager, string name):m_manager(manager), m_name(name){}
	virtual void DealWithRequest(string name, int num)  {}
};
//Common Manager
class CommonManager: public Manager
{
public:
	CommonManager(Manager *manager, string name):Manager(manager,name) {}
	void DealWithRequest(string name, int num) 
	{
		if(num < 500) 
		{
			cout<<"Manager "<<m_name<<" approve"<<name<<" add salary "<<num<<"$"<<endl<<endl;
		}
		else
		{
			cout<<"Manager "<<m_name<<" cannot deal with it，Send it to majordomo"<<endl;
			m_manager->DealWithRequest(name, num);
		}
	}
};
//Majordomo
class Majordomo: public Manager
{
public:
	Majordomo(Manager *manager, string name):Manager(manager,name) {}
	void DealWithRequest(string name, int num) 
	{
		if(num < 1000) 
		{
			cout<<"Majordomo "<<m_name<<" approve "<<name<<" add salary "<<num<<"$"<<endl<<endl;
		}
		else
		{
			cout<<"Majordomo "<<m_name<<" cannot deal with it，send it to GeneralManager "<<endl;
			m_manager->DealWithRequest(name, num);
		}
	}
};

class GeneralManager: public Manager
{
public:
	GeneralManager(Manager *manager, string name):Manager(manager,name) {}
	void DealWithRequest(string name, int num)  
	{
		cout<<"General Manager"<<m_name<<"approve"<<name<<"add salary"<<num<<"$"<<endl<<endl;
	}
};


int main1()
{	
	Manager *general = new GeneralManager(NULL, "A"); 
	Manager *majordomo = new Majordomo(general, "B"); 
	Manager *common = new CommonManager(majordomo, "C"); 
	common->DealWithRequest("D",300);   
	common->DealWithRequest("E", 600);
	common->DealWithRequest("F", 1000);
	delete common;
	delete majordomo; 
	delete general;
	cin.get();
	return 0;
}